#include "show.h"
#include "my_wifi.h"
#include "ui.h"
#include "iic_device.h"

void ShowWifi_info(void){
 //更新wifi信息
 if(wifi_state == 1 && wifi_state_change == 1){//链接上了WiFi
     wifi_state_change = 0;
     lv_label_set_text(ui_WIFIImage0, "");//主页WiFi信号强度
     lv_label_set_text(ui_WIFIImage1, "");//主页WiFi信号强度
     lv_label_set_text(ui_WIFIImage2, "");//主页WiFi信号强度
 
     lv_label_set_text(ui_SSIDlabel,SSID);
     lv_label_set_text(ui_IPlabel,IP);
     lv_label_set_text(ui_wifistatelabel, "已连接");
 }else if(wifi_state == 0){
     wifi_state_change  = 0;
     lv_label_set_text(ui_WIFIImage0, "");//主页WiFi显示关闭
     lv_label_set_text(ui_WIFIImage1, "");//主页WiFi显示关闭
     lv_label_set_text(ui_WIFIImage2, "");//主页WiFi显示关闭
     lv_label_set_text(ui_SSIDlabel,"");
     lv_label_set_text(ui_IPlabel,"");
     lv_label_set_text(ui_wifistatelabel, "未连接");
 }else if(wifi_state == 2 && wifi_state_change == 1){
     wifi_state_change = 0;
     lv_label_set_text(ui_wifistatelabel, "等待配网");
 }else if(wifi_state == 3 && wifi_state_change == 1){
     wifi_state_change = 0;
     lv_label_set_text(ui_wifistatelabel, "正在连接通道");
 }else if(wifi_state == 4 && wifi_state_change == 1){
     wifi_state_change = 0;
     lv_label_set_text(ui_wifistatelabel, "正在连接网络");
 }
}

void show_wifi_streng(void){
    printf("强度：%d\r\n",NET_RSSI);
    if(NET_RSSI<=-90){//<-90
        lv_label_set_text(ui_WIFIImage0, "");//主页WiFi信号强度
        lv_label_set_text(ui_WIFIImage1, "");//主页WiFi信号强度
        lv_label_set_text(ui_WIFIImage2, "");//主页WiFi信号强度
    }else if(NET_RSSI<=-80 && NET_RSSI>-90){//-80~-90
        lv_label_set_text(ui_WIFIImage0, "");//主页WiFi信号强度
        lv_label_set_text(ui_WIFIImage1, "");//主页WiFi信号强度
        lv_label_set_text(ui_WIFIImage2, "");//主页WiFi信号强度
    }else if(NET_RSSI<=-70 && NET_RSSI>-80){//-70~-80
        lv_label_set_text(ui_WIFIImage0, "");//主页WiFi信号强度
        lv_label_set_text(ui_WIFIImage1, "");//主页WiFi信号强度
        lv_label_set_text(ui_WIFIImage2, "");//主页WiFi信号强度
    }else if(NET_RSSI<=-67 && NET_RSSI>-70){//-67~-70
        lv_label_set_text(ui_WIFIImage0, "");//主页WiFi信号强度
        lv_label_set_text(ui_WIFIImage1, "");//主页WiFi信号强度
        lv_label_set_text(ui_WIFIImage2, "");//主页WiFi信号强度
    }else{//>-67
        lv_label_set_text(ui_WIFIImage0, "");//主页WiFi信号强度
        lv_label_set_text(ui_WIFIImage1, "");//主页WiFi信号强度
        lv_label_set_text(ui_WIFIImage2, "");//主页WiFi信号强度
    }
}

void ShowDtaeTime_info(void){

}

void ShowSYSET_info(void){
 lv_label_set_text_fmt(ui_powernum0,"%d%%",electric_quantity);//电量
 lv_label_set_text_fmt(ui_powernum1,"%d%%",electric_quantity);//电量
 lv_label_set_text_fmt(ui_powernum2,"%d%%",electric_quantity);//电量
 lv_label_set_text_fmt(ui_templabel0,"%.1f℃",TEMP_MEASUREMENT);//温度
 lv_label_set_text_fmt(ui_templabel1,"%.1f℃",TEMP_MEASUREMENT);//温度
 lv_label_set_text_fmt(ui_templabel2,"%.1f℃",TEMP_MEASUREMENT);//温度
 lv_label_set_text_fmt(ui_humlabel0,"%.1f%%RH",HUM_MEASUREMENT);//湿度
 lv_label_set_text_fmt(ui_humlabel1,"%.1f%%RH",HUM_MEASUREMENT);//湿度
 lv_label_set_text_fmt(ui_humlabel2,"%.1f%%RH",HUM_MEASUREMENT);//湿度
 if(electric_quantity == 100){
  lv_label_set_text(ui_PowerImage0, "");
  lv_label_set_text(ui_PowerImage1, "");
  lv_label_set_text(ui_PowerImage2, "");
 } else if(81 <= electric_quantity && electric_quantity<= 99){
  lv_label_set_text(ui_PowerImage0, "");
  lv_label_set_text(ui_PowerImage1, "");
  lv_label_set_text(ui_PowerImage2, "");
 } else if(61 <= electric_quantity && electric_quantity<= 80){
  lv_label_set_text(ui_PowerImage0, "");
  lv_label_set_text(ui_PowerImage1, "");
  lv_label_set_text(ui_PowerImage2, "");
 } else if(41 <= electric_quantity && electric_quantity<= 60){
  lv_label_set_text(ui_PowerImage0, "");
  lv_label_set_text(ui_PowerImage1, "");
  lv_label_set_text(ui_PowerImage2, "");
 } else if(21 <= electric_quantity && electric_quantity<= 40){
  lv_label_set_text(ui_PowerImage0, "");
  lv_label_set_text(ui_PowerImage1, "");
  lv_label_set_text(ui_PowerImage2, "");
 } else if(11 <= electric_quantity && electric_quantity<= 20){
  lv_label_set_text(ui_PowerImage0, "");
  lv_label_set_text(ui_PowerImage1, "");
  lv_label_set_text(ui_PowerImage2, "");
 } else if(1 <= electric_quantity && electric_quantity<= 10){
  lv_label_set_text(ui_PowerImage0, "");
  lv_label_set_text(ui_PowerImage1, "");
  lv_label_set_text(ui_PowerImage2, "");
 } else{
  lv_label_set_text(ui_PowerImage0, "");
  lv_label_set_text(ui_PowerImage1, "");
  lv_label_set_text(ui_PowerImage2, "");
 }
 if(electric_quantity>= 21){
     lv_obj_set_style_text_color(ui_PowerImage0, lv_color_hex(0x32CD32), LV_PART_MAIN | LV_STATE_DEFAULT);//绿色
     lv_obj_set_style_text_color(ui_PowerImage1, lv_color_hex(0x32CD32), LV_PART_MAIN | LV_STATE_DEFAULT);//绿色
     lv_obj_set_style_text_color(ui_PowerImage2, lv_color_hex(0x32CD32), LV_PART_MAIN | LV_STATE_DEFAULT);//绿色
 }else if(11 <= electric_quantity && electric_quantity <=20){
     lv_obj_set_style_text_color(ui_PowerImage0, lv_color_hex(0xFFA500), LV_PART_MAIN | LV_STATE_DEFAULT);//橙色
     lv_obj_set_style_text_color(ui_PowerImage1, lv_color_hex(0xFFA500), LV_PART_MAIN | LV_STATE_DEFAULT);//橙色
     lv_obj_set_style_text_color(ui_PowerImage2, lv_color_hex(0xFFA500), LV_PART_MAIN | LV_STATE_DEFAULT);//橙色
 }else{
     lv_obj_set_style_text_color(ui_PowerImage0, lv_color_hex(0xFF0000), LV_PART_MAIN | LV_STATE_DEFAULT);//红色
     lv_obj_set_style_text_color(ui_PowerImage1, lv_color_hex(0xFF0000), LV_PART_MAIN | LV_STATE_DEFAULT);//红色
     lv_obj_set_style_text_color(ui_PowerImage2, lv_color_hex(0xFF0000), LV_PART_MAIN | LV_STATE_DEFAULT);//红色
 }
}